FROM golang:1.22 as builder

WORKDIR /usr/local/alibabacloudkmsagent

COPY go.mod go.sum ./
RUN go mod download

COPY main.go main.go
COPY cmd/ cmd/
COPY configs/ configs/
COPY internal/ internal/

RUN CGO_ENABLED=0 GOOS=linux GOARCH=amd64 go build .

FROM scratch

WORKDIR /usr/local/alibabacloudkmsagent

COPY --from=builder /usr/local/alibabacloudkmsagent/alibabacloud-kms-agent .
COPY --from=builder /usr/local/alibabacloudkmsagent/configs/config.toml .

CMD ["./alibabacloud-kms-agent", "agent", "./config.toml"]
